<?php
namespace App\Model\Appfc114;

use Illuminate\Database\Eloquent\Model as Model;
use Illuminate\Database\Capsule\Manager as DB;

class SysUser extends Model {

    protected $table = "sys_user as a";
    public $timestamps = false;


    public function getDetail($id, $field ="a.id"){
        //DB::connection()->enableQueryLog();
        $row = $this
            ->leftJoin("sys_poststation as b","a.orgstruct_id","=","b.orgstruct_id")
            ->where($field,$id)
            ->first(array('a.id','a.orgstruct_id','a.department_id','a.user_type','a.user_name','a.true_name','a.nickname','a.password','a.openid','a.headimgurl','a.mobile','a.is_admin','a.city_code','a.active','a.login_date','b.name as role_name','b.id as poststation_id'));
        //print_r(DB::getQueryLog());exit;
        return $row;
    }

    public function getListItems($page, $perpage) {
        return $this
            ->orderByRaw('id DESC')
            ->limit(($page - 1) * $perpage, $perpage)
            ->get();
    }

    public function getListTotal($state="") {
        $total = $this->where($state)->count();
        return intval($total);
    }
}
